classes: jobserver: support gnu make fifo jobserver
RFC PATCH 1/5 classes: jobserver: support gnu make fifo jobserver
Add a class to implement the gnu make fifo style jobserver. The class can be activated by symply adding an INHERIT += "jobserver" to the local configuration.
Furthermore, one can configure an external jobserver (i.e. a server shared between multiple builds), by configured the JOBSERVER_FIFO variable to point at an existing jobserver fifo.
The jobserver class uses the fifo style jobserver, which doesn't require passing open file descriptors around. It does, however, require make-4.4, which isn't available in common distro yet. To work around this, the class make all recipes (except make and its dependencies itself) depend on virtual/make-native.
--- meta/classes-global/jobserver.bbclass | 80 +++++++++++++++++++++++++++ meta/conf/bitbake.conf | 2 +- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 meta/classes-global/jobserver.bbclass
meta/classes-global/jobserver.bbclass new file +80 -0
@@ -0,0 +1,80 @@ +JOBSERVER_FIFO ?= "" +JOBSERVER_FIFO[doc] = "Path to external jobserver fifo to use instead of creating a per-build server." + +addhandler jobserver_setup_fifo +jobserver_setup_fifo[eventmask] = "bb.event.ConfigParsed" + +python jobserver_setup_fifo() { + # don't setup a per-build fifo, if an external one is configured + if d.getVar("JOBSERVER_FIFO"): + return + + # don't use a job-server if no parallelism is configured + jobs = oe.utils.parallel_make(d) + if jobs in (None, 1): + return + + # reduce jobs by one as a token has implicitly been handed to the + # process requesting tokens + jobs -= 1 + + fifo = d.getVar("TMPDIR") + "/jobserver_fifo" + + # and old fifo might be lingering; remove it + if os.path.exists(fifo): + os.remove(fifo) + + # create a new fifo to use for communicating tokens + os.mkfifo(fifo) + + # fill the fifo with the number of tokens to hand out + wfd = os.open(fifo, os.O_RDWR) + written = os.write(wfd, b"+" * jobs) + if written != (jobs): + bb.error("Failed to fil make fifo: {} != {}".format(written, jobs)) + + # configure the per-build fifo path to use + d.setVar("JOBSERVER_FIFO", fifo) +} + +python () { + # don't configure the fifo if none is defined + fifo = d.getVar("JOBSERVER_FIFO") + if not fifo: + return + + # avoid making make-native or its dependencies depend on make-native itself + if d.getVar("PN") in ( + "make-native", + "libtool-native", + "pkgconfig-native", + "automake-native", + "autoconf-native", + "m4-native", + "texinfo-dummy-native", + "gettext-minimal-native", + "quilt-native", + "gnu-config-native", + ): + return + + # don't make unwilling recipes depend on make-native + if d.getVar('INHIBIT_DEFAULT_DEPS', False): + return + + # make other recipes depend on make-native to make sure it is new enough to + # support the --jobserver-auth=fifo:<path> syntax (from make-4.4 and onwards) + d.appendVar("DEPENDS", " virtual/make-native") + + # disable the "-j <jobs>" flag, as that overrides the jobserver fifo tokens + d.setVar("PARALLEL_MAKE", "") + d.setVar("PARALLEL_MAKEINST", "") + + # set and export the jobserver in the environment + d.appendVar("MAKEFLAGS", " --jobserver-auth=fifo:" + fifo) + d.setVarFlag("MAKEFLAGS", "export", "1") + + # ignore the joberserver argument part of MAKEFLAGS in the hash, as that + # shouldn't change the build output + d.appendVarFlag("MAKEFLAGS", "vardepvalueexclude", "| --jobserver-auth=fifo:" + fifo) +}
meta/conf/bitbake.conf +1 -1
@@ -946,7 +946,7 @@ BB_HASHEXCLUDE_COMMON ?= "TMPDIR FILE PATH PWD BB_TASKHASH BBPATH BBSERVER DL_DI BB_WORKERCONTEXT BB_LIMITEDDEPS BB_UNIHASH extend_recipe_sysroot DEPLOY_DIR \ SSTATE_HASHEQUIV_METHOD SSTATE_HASHEQUIV_REPORT_TASKDATA \ SSTATE_HASHEQUIV_OWNER CCACHE_TOP_DIR BB_HASHSERVE GIT_CEILING_DIRECTORIES \ - OMP_NUM_THREADS BB_CURRENTTASK" + OMP_NUM_THREADS BB_CURRENTTASK JOBSERVER_FIFO" BB_BASEHASH_IGNORE_VARS ?= "${BB_HASHEXCLUDE_COMMON} PSEUDO_IGNORE_PATHS BUILDHISTORY_DIR \ SSTATE_DIR SOURCE_DATE_EPOCH RUST_BUILD_SYS RUST_HOST_SYS RUST_TARGET_SYS" BB_HASHCONFIG_IGNORE_VARS ?= "${BB_HASHEXCLUDE_COMMON} DATE TIME SSH_AGENT_PID \
Signature · 1 line
2.41.0
RFC PATCH 2/5 scripts: build-env: allow passing JOBSERVER_FIFO from environment
Sharing a common jobserver fifo between multiple (containerized) builds is much easier, if an administrator can configure said jobserver fifo path in the environment. Append the JOBSERVER_FIFO variable name to the list of variables configurable through the environment.
--- scripts/oe-buildenv-internal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/oe-buildenv-internal +1 -1
@@ -112,7 +112,7 @@ HTTPS_PROXY https_proxy FTP_PROXY ftp_proxy FTPS_PROXY ftps_proxy ALL_PROXY \ all_proxy NO_PROXY no_proxy SSH_AGENT_PID SSH_AUTH_SOCK BB_SRCREV_POLICY \ SDKMACHINE BB_NUMBER_THREADS BB_NO_NETWORK PARALLEL_MAKE GIT_PROXY_COMMAND \ SOCKS5_PASSWD SOCKS5_USER SCREENDIR STAMPS_DIR BBPATH_EXTRA BB_SETSCENE_ENFORCE \ -BB_LOGCONFIG" +BB_LOGCONFIG JOBSERVER_FIFO" BB_ENV_PASSTHROUGH_ADDITIONS="$(echo $BB_ENV_PASSTHROUGH_ADDITIONS $BB_ENV_PASSTHROUGH_ADDITIONS_OE | tr ' ' '\n' | LC_ALL=C sort --unique | tr '\n' ' ')"
Signature · 1 line
2.41.0
RFC PATCH 3/5 ninja: build modified version with GNU Make jobserver support
In reply to Martin HundebøllNinja doesn't (yet) support the GNU Make jobserver out of the box, but there is a pull request adding that support[1]. Switch the SRC_URI and SRCREV to point at the source of that pull request, to make ninja play nicely together with the recently added jobserver class.
---
.../ninja/{ninja_1.11.1.bb => ninja_1.12.0.bb} | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
rename meta/recipes-devtools/ninja/{ninja_1.11.1.bb => ninja_1.12.0.bb} (84%)meta/recipes-devtools/ninja/ninja_1.12.0.bb renamed from meta/recipes-devtools/ninja/ninja_1.11.1.bb +2 -2
@@ -6,9 +6,9 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=a81586a64ad4e476c791cda7e2f2c52e" DEPENDS = "re2c-native ninja-native" -SRCREV = "a524bf3f6bacd1b4ad85d719eed2737d8562f27a" +SRCREV = "c9e21dbbc4c746ba397c0f9bec5f65c99f783c08" -SRC_URI = "git://github.com/ninja-build/ninja.git;branch=release;protocol=https" +SRC_URI = "git://github.com/stefanb2/ninja.git;branch=topic-issue-1139-part-3-jobserver-fifo;protocol=https" UPSTREAM_CHECK_GITTAGREGEX = "v(?P<pver>.*)" S = "${WORKDIR}/git"
Signature · 1 line
2.41.0
Re: [OE-core] [RFC PATCH 3/5] ninja: build modified version with GNU Make jobserver support
Thanks, make/ninja jobserver is something we've been talking about since forever, and it's great to see actual code.
I suppose the biggest obstacle is that ninja support hasn't yet landed upstream, and I'd like to ensure it does. Also, a link to the pull request is missing? :)
Alex
Quoted 43 lines · Martin Hundeb?ll
Ninja doesn't (yet) support the GNU Make jobserver out of the box, but there is a pull request adding that support[1]. Switch the
SRC_URIand SRCREV to point at the source of that pull request, to make ninja play nicely together with the recently added jobserver class.Signed-off-by Martin Hundebøll <[email protected]>--- .../ninja/{ninja_1.11.1.bb => ninja_1.12.0.bb} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename meta/recipes-devtools/ninja/{ninja_1.11.1.bb => ninja_1.12.0.bb} (84%)meta/recipes-devtools/ninja/ninja_1.12.0.bb renamed from meta/recipes-devtools/ninja/ninja_1.11.1.bb +2
-3@@ -6,9 +6,9 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=a81586a64ad4e476c791cda7e2f2c52e" DEPENDS = "re2c-native ninja-native" -SRCREV = "a524bf3f6bacd1b4ad85d719eed2737d8562f27a" +SRCREV = "c9e21dbbc4c746ba397c0f9bec5f65c99f783c08" -SRC_URI = "git://github.com/ninja-build/ninja.git;branch=release;protocol=https" +SRC_URI = "git://github.com/stefanb2/ninja.git;branch=topic-issue-1139-part-3-jobserver-fifo;protocol=https" UPSTREAM_CHECK_GITTAGREGEX = "v(?P<pver>.*)" S = "${WORKDIR}/git" --2.41.0
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#186825): https://lists.openembedded.org/g/openembedded-core/message/186825
Mute This Topic: https://lists.openembedded.org/mt/101009093/1686489
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [OE-core] [RFC PATCH 3/5] ninja: build modified version with GNU Make jobserver support
Quoted 7 lines · Alexander Kanavin
Thanks, make/ninja jobserver is something we've been talking about since forever, and it's great to see actual code.
I suppose the biggest obstacle is that ninja support hasn't yet landed
upstream, and I'd like to ensure it does. Also, a link to the pull request is missing? :)
Indeed, upstream seems to ignore the pull request :(
Link references are like attachments: easy to forget... Here it is:
https://github.com/ninja-build/ninja/issues/1139
// Martin
Quoted 58 lines
Quoted 56 lines · Martin Hundeb?ll
Ninja doesn't (yet) support the GNU Make jobserver out of the box, but
there is a pull request adding that support[1]. Switch theSRC_URIand
SRCREV to point at the source of that pull request, to make ninja play
nicely together with the recently added jobserver class.Signed-off-by Martin Hundebøll <[email protected]>---
.../ninja/{ninja_1.11.1.bb => ninja_1.12.0.bb} | 4
++--1 file changed, 2 insertions(+), 2 deletions(-)rename meta/recipes-devtools/ninja/{ninja_1.11.1.bb => ninja_1.12.0.bb} (84%)
meta/recipes-devtools/ninja/ninja_1.12.0.bb renamed from meta/recipes-devtools/ninja/ninja_1.11.1.bb +0
-0@@ -6,9 +6,9 @@ LIC_FILES_CHKSUM ="file://COPYING;md5=a81586a64ad4e476c791cda7e2f2c52e"
DEPENDS = "re2c-native ninja-native"
meta/recipes-devtools/ninja/ninja_1.12.0.bb renamed from meta/recipes-devtools/ninja/ninja_1.11.1.bb +1
-2-SRCREV = "a524bf3f6bacd1b4ad85d719eed2737d8562f27a" +SRCREV = "c9e21dbbc4c746ba397c0f9bec5f65c99f783c08" -SRC_URI = "git://github.com/ninja-build/ninja.git;branch=release;protocol=https"
+SRC_URI = "git://github.com/stefanb2/ninja.git;branch=topic-issue-1139-part-3-jobserver-fifo;protocol=https"UPSTREAM_CHECK_GITTAGREGEX= "v(?P<pver>.*)"S = "${WORKDIR}/git"
--
2.41.0-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#186825):
https://lists.openembedded.org/g/openembedded-core/message/186825
Mute This Topic:
https://lists.openembedded.org/mt/101009093/1686489
Group Owner: [email protected] Unsubscribe:
https://lists.openembedded.org/g/openembedded-core/unsub [
[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [OE-core] [RFC PATCH 3/5] ninja: build modified version with GNU Make jobserver support
If previous PRs have stalled, it may help to open a fresh one, which you can drive yourself. You can reuse and rebase previous patches by others as needed.
Alex
Quoted 76 lines · Martin Hundebøll
Quoted 7 lines · Alexander Kanavin
Thanks, make/ninja jobserver is something we've been talking about since forever, and it's great to see actual code.
I suppose the biggest obstacle is that ninja support hasn't yet landed
upstream, and I'd like to ensure it does. Also, a link to the pull request is missing? :)Indeed, upstream seems to ignore the pull request :(
Link references are like attachments: easy to forget... Here it is:
https://github.com/ninja-build/ninja/issues/1139// Martin
Quoted 58 lines
Quoted 56 lines · Martin Hundeb?ll
Ninja doesn't (yet) support the GNU Make jobserver out of the box, but
there is a pull request adding that support[1]. Switch theSRC_URIand
SRCREV to point at the source of that pull request, to make ninja play
nicely together with the recently added jobserver class.Signed-off-by Martin Hundebøll <[email protected]>--- .../ninja/{ninja_1.11.1.bb => ninja_1.12.0.bb} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename meta/recipes-devtools/ninja/{ninja_1.11.1.bb =>ninja_1.12.0.bb} (84%)
meta/recipes-devtools/ninja/ninja_1.12.0.bb renamed from meta/recipes-devtools/ninja/ninja_1.11.1.bb +0
-0@@ -6,9 +6,9 @@ LIC_FILES_CHKSUM ="file://COPYING;md5=a81586a64ad4e476c791cda7e2f2c52e"
DEPENDS = "re2c-native ninja-native"
meta/recipes-devtools/ninja/ninja_1.12.0.bb renamed from meta/recipes-devtools/ninja/ninja_1.11.1.bb +1
-2-SRCREV = "a524bf3f6bacd1b4ad85d719eed2737d8562f27a" +SRCREV = "c9e21dbbc4c746ba397c0f9bec5f65c99f783c08" -SRC_URI = "git://github.com/ninja-build/ninja.git;branch=release;protocol=https"
+SRC_URI = "git://github.com/stefanb2/ninja.git;branch=topic-issue-1139-part-3-jobserver-fifo;protocol=https"
UPSTREAM_CHECK_GITTAGREGEX= "v(?P<pver>.*)"S = "${WORKDIR}/git"
--
2.41.0-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#186825):
https://lists.openembedded.org/g/openembedded-core/message/186825
Mute This Topic:
https://lists.openembedded.org/mt/101009093/1686489
Group Owner: [email protected] Unsubscribe:
https://lists.openembedded.org/g/openembedded-core/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [OE-core] [RFC PATCH 3/5] ninja: build modified version with GNU Make jobserver support
In reply to Martin HundebøllQuoted 20 lines · Martin Hundeb?ll
Ninja doesn't (yet) support the GNU Make jobserver out of the box, but there is a pull request adding that support[1]. Switch the
SRC_URIand SRCREV to point at the source of that pull request, to make ninja play nicely together with the recently added jobserver class.Signed-off-by Martin Hundebøll <[email protected]>--- .../ninja/{ninja_1.11.1.bb => ninja_1.12.0.bb} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename meta/recipes-devtools/ninja/{ninja_1.11.1.bb => ninja_1.12.0.bb} (84%)meta/recipes-devtools/ninja/ninja_1.12.0.bb renamed from meta/recipes-devtools/ninja/ninja_1.11.1.bb +0
-0
meta/recipes-devtools/ninja/ninja_1.12.0.bb LIC_FILES_CHKSUM = "file://COPYING;md5=a81586a64ad4e476c791cda7e2f2c52e" · line 11
Quoted 8 lines
meta/recipes-devtools/ninja/ninja_1.12.0.bb renamed from meta/recipes-devtools/ninja/ninja_1.11.1.bb +2
-2@@ -6,9 +6,9 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=a81586a64ad4e476c791cda7e2f2c52e" DEPENDS = "re2c-native ninja-native" -SRCREV = "a524bf3f6bacd1b4ad85d719eed2737d8562f27a" +SRCREV = "c9e21dbbc4c746ba397c0f9bec5f65c99f783c08" -SRC_URI = "git://github.com/ninja-build/ninja.git;branch=release;protocol=https" +SRC_URI = "git://github.com/stefanb2/ninja.git;branch=topic-issue-1139-part-3-jobserver-fifo;protocol=https"
This is a little concerning, as we are pointing to a fork here and quite a lot depend on ninja now
a days. so I wonder whats the status of the patches and likelyhood of them going upstream
in anycase, we should pick the patches instead of switching SRC_URI
Quoted 15 lines
meta/recipes-devtools/ninja/ninja_1.12.0.bb renamed from meta/recipes-devtools/ninja/ninja_1.11.1.bb +0
-1UPSTREAM_CHECK_GITTAGREGEX = "v(?P<pver>.*)" S = "${WORKDIR}/git" --2.41.0
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#186825): https://lists.openembedded.org/g/openembedded-core/message/186825
Mute This Topic: https://lists.openembedded.org/mt/101009093/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [OE-core] [RFC PATCH 3/5] ninja: build modified version with GNU Make jobserver support
Aug 28, 2023 19:16:28 Khem Raj <[email protected]>:
Quoted 27 lines · Martin Hundeb?ll
Quoted 26 lines
Ninja doesn't (yet) support the GNU Make jobserver out of the box, but there is a pull request adding that support[1]. Switch the
SRC_URIand SRCREV to point at the source of that pull request, to make ninja play nicely together with the recently added jobserver class.Signed-off-by Martin Hundebøll <[email protected]>---
.../ninja/{ninja_1.11.1.bb => ninja_1.12.0.bb} | 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)rename meta/recipes-devtools/ninja/{ninja_1.11.1.bb => ninja_1.12.0.bb} (84%)
meta/recipes-devtools/ninja/ninja_1.12.0.bb renamed from meta/recipes-devtools/ninja/ninja_1.11.1.bb +0
-0@@ -6,9 +6,9 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=a81586a64ad4e476c791cda7e2f2c52e"DEPENDS = "re2c-native ninja-native"
meta/recipes-devtools/ninja/ninja_1.12.0.bb renamed from meta/recipes-devtools/ninja/ninja_1.11.1.bb +1
-1-SRCREV = "a524bf3f6bacd1b4ad85d719eed2737d8562f27a" +SRCREV = "c9e21dbbc4c746ba397c0f9bec5f65c99f783c08"
Quoted 8 lines
meta/recipes-devtools/ninja/ninja_1.12.0.bb LIC_FILES_CHKSUM = "file://COPYING;md5=a81586a64ad4e476c791cda7e2f2c52e" · line 11
Quoted 2 lines
meta/recipes-devtools/ninja/ninja_1.12.0.bb renamed from meta/recipes-devtools/ninja/ninja_1.11.1.bb +1
-1-SRC_URI = "git://github.com/ninja-build/ninja.git;branch=release;protocol=https" +SRC_URI = "git://github.com/stefanb2/ninja.git;branch=topic-issue-1139-part-3-jobserver-fifo;protocol=https"This is a little concerning, as we are pointing to a fork here and quite a lot depend on ninja now
a days. so I wonder whats the status of the patches and likelyhood of them going upstream
in anycase, we should pick the patches instead of switchingSRC_URI
Yes, I agree that we shouldn't change uri to a fork; hence the RFC... Maybe I should try to put some pressure on ninja upstream to consider the pull request...
I can look into whether a separate patch is feasible...
Quoted 15 lines
Quoted 15 lines
UPSTREAM_CHECK_GITTAGREGEX= "v(?P<pver>.*)"S = "${WORKDIR}/git"
--
2.41.0-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#186825): https://lists.openembedded.org/g/openembedded-core/message/186825
Mute This Topic: https://lists.openembedded.org/mt/101009093/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [OE-core] [RFC PATCH 3/5] ninja: build modified version with GNU Make jobserver support
Quoted 46 lines · Martin Hundeb?ll
Aug 28, 2023 19:16:28 Khem Raj <[email protected]>:
> On Mon, Aug 28, 2023 at 5:48 AM Martin Hundeb?ll <[email protected]> wrote:
>>
>> Ninja doesn't (yet) support the GNU Make jobserver out of the box, but
>> there is a pull request adding that support[1]. Switch theSRC_URIand
>> SRCREV to point at the source of that pull request, to make ninja play
>> nicely together with the recently added jobserver class. >>
>> Signed-off-by: Martin Hundebøll <[email protected]>
>> ---
>> .../ninja/{ninja_1.11.1.bb => ninja_1.12.0.bb} | 4
++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>> rename meta/recipes-devtools/ninja/{ninja_1.11.1.bb => ninja_1.12.0.bb} (84%)
>>
>> diff --git a/meta/recipes-devtools/ninja/ninja_1.11.1.bb b/meta/recipes-devtools/ninja/ninja_1.12.0.bb
>> similarity index 84%
>> rename from meta/recipes-devtools/ninja/ninja_1.11.1.bb >> rename to meta/recipes-devtools/ninja/ninja_1.12.0.bb >> index8e297ec4d4..9abdd40a92100644
>> --- a/meta/recipes-devtools/ninja/ninja_1.11.1.bb
>> +++ b/meta/recipes-devtools/ninja/ninja_1.12.0.bb
>> @@ -6,9 +6,9 @@LIC_FILES_CHKSUM= "file://COPYING;md5=a81586a64ad4e476c791cda7e2f2c52e"
>>
>> DEPENDS = "re2c-native ninja-native"
>>
>> -SRCREV = "a524bf3f6bacd1b4ad85d719eed2737d8562f27a" >> +SRCREV = "c9e21dbbc4c746ba397c0f9bec5f65c99f783c08" >>
>> -SRC_URI = "git://github.com/ninja-build/ninja.git;branch=release;protocol=https"
>> +SRC_URI = "git://github.com/stefanb2/ninja.git;branch=topic-issue-1139-part-3-jobserver-fifo;protocol=https"
>
> This is a little concerning, as we are pointing to a fork here and > quite a lot depend on ninja now
> a days. so I wonder whats the status of the patches and likelyhood
Quoted 8 lines
of
> them going upstream
> in anycase, we should pick the patches instead of switchingSRC_URI
Yes, I agree that we shouldn't change uri to a fork; hence the RFC... Maybe I should try to put some pressure on ninja upstream to consider the pull request...
One option could be to use the kitware fork of ninja, which supports the fifo makeserver:
https://github.com/Kitware/ninja
This is what buildroot does:
https://gitlab.com/buildroot.org/buildroot/-/blob/master/package/ninja/ninja.mk
// Martin
Quoted 23 lines
>>
UPSTREAM_CHECK_GITTAGREGEX= "v(?P<pver>.*)"
>>
>> S = "${WORKDIR}/git"
>> --
>> 2.41.0
>>
>>
>>
>>-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#186841):
https://lists.openembedded.org/g/openembedded-core/message/186841
Mute This Topic: https://lists.openembedded.org/mt/101009093/3618414
Group Owner: [email protected] Unsubscribe:
https://lists.openembedded.org/g/openembedded-core/unsub [
[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
RFC PATCH 4/5 qemu: enable parallel builds when using the jobserver class
In reply to Martin HundebøllIf the jobserver class is enabled, the PARALLEL_MAKE variable is unset in favor of configuring a shared jobserver in the MAKEFLAGS variable. However, the qemu makefile translates the missing -j<N> argument to -j1 when calling into meson / ninja. Avoid this by setting -j without a value. For normal/GNU make, this can result in a fork bomb, but for ninja, it simply makes it use the jobserver fifa instead.
--- meta/recipes-devtools/qemu/qemu.inc | 5 +++++ 1 file changed, 5 insertions(+)
meta/recipes-devtools/qemu/qemu.inc +5 -0
@@ -110,6 +110,11 @@ EXTRA_OECONF = " \ ${PACKAGECONFIG_CONFARGS} \ " +# Avoid the qemu makefile treating a missing `-j<N>` argument as `-j1` when +# calling meson / ninja. This happens when the `jobserver` class is used, since +# it manages parallelism in the MAKEFLAGS variable instead of PARALLEL_MAKE. +EXTRA_OEMAKE:append = "${@' -j' if d.getVar('JOBSERVER_FIFO') else ''}" + B = "${WORKDIR}/build" #EXTRA_OECONF:append = " --python=${HOSTTOOLS_DIR}/python3"
Signature · 1 line
2.41.0
Re: [OE-core] [RFC PATCH 4/5] qemu: enable parallel builds when using the jobserver class
Thanks for the patch set Martin!
Quoted 6 lines · Martin Hundeb?ll via lists.openembedded.org
If the jobserver class is enabled, the
PARALLEL_MAKEvariable is unset in favor of configuring a shared jobserver in the MAKEFLAGS variable. However, the qemu makefile translates the missing-j<N>argument to-j1when calling into meson / ninja. Avoid this by setting-jwithout a value. For normal/GNU make, this can result in a fork bomb, but for ninja, it simply makes it use the jobserver fifa instead.
small typo: s/fifa/fifo/
Quoted 11 lines
Signed-off-by Martin Hundebøll<[email protected]>--- meta/recipes-devtools/qemu/qemu.inc | 5 +++++ 1 file changed, 5 insertions(+)meta/recipes-devtools/qemu/qemu.inc +0
-0
meta/recipes-devtools/qemu/qemu.inc EXTRA_OECONF = " \ · line 117
Quoted 8 lines
meta/recipes-devtools/qemu/qemu.inc +5
-0@@ -110,6 +110,11 @@ EXTRA_OECONF = " \ ${PACKAGECONFIG_CONFARGS} \ " +# Avoid the qemu makefile treating a missing `-j<N>` argument as `-j1` when +# calling meson / ninja. This happens when the `jobserver` class is used, since +# it manages parallelism in the MAKEFLAGS variable instead of PARALLEL_MAKE. +EXTRA_OEMAKE:append ="${@' -j' if d.getVar('JOBSERVER_FIFO') else ''}" +
Is there, or should there be, an upstream bug report/PR for this?
To save other from checking, this is from 2020:
qemu.git on master
❯ git blame Makefile | rg j109e93326e44 (Paolo Bonzini 2020-08-13 09:28:11 -0400 145) $(filter-out -j, $(lastword -j1 $(filter -l% -j%, $(MAKEFLAGS)))) \
09e93326e4 build: replace ninjatool with ninja
https://gitlab.com/qemu-project/qemu/-/commit/09e93326e4
I've applied the patch set and will do a few builds on a old 24 core system and maybe other systems.
Do you have any information on the impact when using the job server?
I suspect that adding openssl to an image might be a good use case since it's is a highly parallel build. Are there other packages that don't depend on openssl that typically run at the same time and can use loads of cores for a long time? If not, I may try out a Nodejs + chromium + webkitgtk + ??? build!
../Randy
Quoted 12 lines
meta/recipes-devtools/qemu/qemu.inc +0
-1B = "${WORKDIR}/build" #EXTRA_OECONF:append = " --python=${HOSTTOOLS_DIR}/python3" -=-=-=-=-=-=-=-=-=-=-=-Links: You receive all messages sent to this group.
View/Reply Online (#186827):https://lists.openembedded.org/g/openembedded-core/message/186827 Mute This Topic:https://lists.openembedded.org/mt/101009095/3616765
Group Owner:[email protected] Unsubscribe:https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Signature · 2 lines
# Randy MacLeod # Wind River Linux
RFC PATCH 5/5 contrib: add python service and systemd unit to run shared jobserver
In reply to Martin HundebøllFor CI setups that might end up building multiple yocto builds in parallel, a shared jobserver can reduce the total load of the system. Setting up such a jobserver is simple, but it does require a process hanging around to keep the jobserver fifo open (to avoid blocking token requests).
Add a simple python script that creates such a jobserver fifo and waits forever. Also add a systemd unit file to start the python service at boot.
The systemd unit can be installed in $HOME/.config/systemd/user/, but one might need to add a droplet config (i.e. systemctl --user edit jobserver.service) to setup the PYTHONPATH variable to make the python script loadable.
--- contrib/jobserver/jobserver.py | 78 +++++++++++++++++++++++++++++ contrib/jobserver/jobserver.service | 10 ++++ 2 files changed, 88 insertions(+) create mode 100644 contrib/jobserver/jobserver.py create mode 100644 contrib/jobserver/jobserver.service
contrib/jobserver/jobserver.py new file +78 -0
@@ -0,0 +1,78 @@ +#!/usr/bin/env python3 + +from pathlib import Path +from threading import Event +import argparse +import os +import shutil +import signal + +resumed = Event() +runtime_dir = os.environ.get("XDG_RUNTIME_DIR", "/run") + +def signal_handler(signum, _frame): + """Wait for an external signal exit the process gracefully.""" + resumed.set() + + +def main(path, user, group, mode, jobs): + """Setup a fifo to used as jobserver shared between builds.""" + try: + path.unlink(missing_ok=True) + os.mkfifo(path) + shutil.chown(path, user, group) + os.chmod(path, mode) + except (FileNotFoundError, PermissionError) as exc: + raise SystemExit(f"failed to create fifo: {path}: {exc.strerror}") + + print(f"jobserver: {path}: {jobs} jobs") + fifo = os.open(path, os.O_RDWR) + os.write(fifo, b"+" * jobs) + + print("jobserver: ready; waiting indefinitely") + signal.signal(signal.SIGTERM, signal_handler) + signal.signal(signal.SIGINT, signal_handler) + resumed.wait() + + print("jobserver: exiting") + path.unlink() + os.close(fifo) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + prog='Make jobserver', + description='Simple application to instantiate a jobserver fifo and hang around', + ) + parser.add_argument( + "--mode", + help="Permission to apply to jobserver fifo", + type=lambda v: int(v, 8), + default=0o0666, + ) + parser.add_argument( + "--user", + help="Username or id to assign ownership of fifo to", + default=os.getuid(), + ) + parser.add_argument( + "--group", + help="Groupname of id to assign ownership of fifo to", + default=os.getgid(), + ) + parser.add_argument( + "path", + help="Path to jobserver fifo path", + type=Path, + nargs='?', + default=f"{runtime_dir}/jobserver", + ) + parser.add_argument( + "jobs", + help="Number of tokens to load jobserver with", + type=int, + nargs='?', + default=os.cpu_count(), + ) + args = parser.parse_args() + main(args.path, args.user, args.group, args.mode, args.jobs)
contrib/jobserver/jobserver.service new file +10 -0
@@ -0,0 +1,10 @@ +[Unit] +Description=Shared jobserver fifo + +[Service] +Type=simple +Environment=PYTHONUNBUFFERED=1 +ExecStart=python jobserver.py + +[Install] +WantedBy=multi-user.target
Signature · 1 line
2.41.0
Aug 28, 2023 14:48:46 Martin Hundebøll <[email protected]>:
Quoted 84 lines
Add a class to implement the gnu make fifo style jobserver. The class can be activated by symply adding an
INHERIT += "jobserver"to the local configuration.Furthermore, one can configure an external jobserver (i.e. a server shared between multiple builds), by configured the
JOBSERVER_FIFOvariable to point at an existing jobserver fifo.The jobserver class uses the fifo style jobserver, which doesn't require passing open file descriptors around. It does, however, require make-4.4, which isn't available in common distro yet. To work around this, the class make all recipes (except make and its dependencies itself) depend on
virtual/make-native.Signed-off-by Martin Hundebøll <[email protected]>---
meta/classes-global/jobserver.bbclass | 80 +++++++++++++++++++++++++++ meta/conf/bitbake.conf | 2 +-2 files changed, 81 insertions(+), 1 deletion(-)create mode 100644 meta/classes-global/jobserver.bbclass
meta/classes-global/jobserver.bbclass new file +57
-0@@ -0,0 +1,80 @@ +JOBSERVER_FIFO ?= "" +JOBSERVER_FIFO[doc] = "Path to external jobserver fifo to use instead of creating a per-build server." + +addhandler jobserver_setup_fifo +jobserver_setup_fifo[eventmask] = "bb.event.ConfigParsed" + +python jobserver_setup_fifo() { + # don't setup a per-build fifo, if an external one is configured + if d.getVar("JOBSERVER_FIFO"): + return + + # don't use a job-server if no parallelism is configured + jobs = oe.utils.parallel_make(d) + if jobs in (None, 1): + return + + # reduce jobs by one as a token has implicitly been handed to the + # process requesting tokens + jobs -= 1 + + fifo = d.getVar("TMPDIR") + "/jobserver_fifo" + + # and old fifo might be lingering; remove it + if os.path.exists(fifo): + os.remove(fifo) + + # create a new fifo to use for communicating tokens + os.mkfifo(fifo) + + # fill the fifo with the number of tokens to hand out + wfd = os.open(fifo, os.O_RDWR) + written = os.write(wfd, b"+" * jobs) + if written != (jobs): + bb.error("Failed to fil make fifo: {} != {}".format(written, jobs)) + + # configure the per-build fifo path to use + d.setVar("JOBSERVER_FIFO", fifo) +} + +python () { + # don't configure the fifo if none is defined + fifo = d.getVar("JOBSERVER_FIFO") + if not fifo: + return + + # avoid making make-native or its dependencies depend on make-native itself + if d.getVar("PN") in ( + "make-native", + "libtool-native", + "pkgconfig-native", + "automake-native", + "autoconf-native", + "m4-native", + "texinfo-dummy-native", + "gettext-minimal-native", + "quilt-native", + "gnu-config-native",
meta/classes-global/jobserver.bbclass line 67
Quoted 10 lines
meta/classes-global/jobserver.bbclass new file +10
-0+ ): + return + + # don't make unwilling recipes depend on make-native + if d.getVar('INHIBIT_DEFAULT_DEPS', False): + return + + # make other recipes depend on make-native to make sure it is new enough to + # support the --jobserver-auth=fifo:<path> syntax (from make-4.4 and onwards) + d.appendVar("DEPENDS", " virtual/make-native")
I would like some feedback on this part, i.e. changing package dependencies depending on a pure build-configuration like this. I would prefer if the build didn't change at all when enabling the jobserver class, which would require adding virtual/make-native to the base dependencies regardless of this class. Would that be acceptable?
Quoted 27 lines
meta/classes-global/jobserver.bbclass new file +12
-0+ # disable the "-j <jobs>" flag, as that overrides the jobserver fifo tokens + d.setVar("PARALLEL_MAKE", "") + d.setVar("PARALLEL_MAKEINST", "") + + # set and export the jobserver in the environment + d.appendVar("MAKEFLAGS", " --jobserver-auth=fifo:" + fifo) + d.setVarFlag("MAKEFLAGS", "export", "1") + + # ignore the joberserver argument part of MAKEFLAGS in the hash, as that + # shouldn't change the build output + d.appendVarFlag("MAKEFLAGS", "vardepvalueexclude", "| --jobserver-auth=fifo:" + fifo) +}meta/conf/bitbake.conf +1
-1@@ -946,7 +946,7 @@ BB_HASHEXCLUDE_COMMON ?= "TMPDIR FILE PATH PWD BB_TASKHASH BBPATH BBSERVER DL_DI BB_WORKERCONTEXT BB_LIMITEDDEPS BB_UNIHASH extend_recipe_sysroot DEPLOY_DIR \ SSTATE_HASHEQUIV_METHOD SSTATE_HASHEQUIV_REPORT_TASKDATA \ SSTATE_HASHEQUIV_OWNER CCACHE_TOP_DIR BB_HASHSERVE GIT_CEILING_DIRECTORIES \ - OMP_NUM_THREADS BB_CURRENTTASK" + OMP_NUM_THREADS BB_CURRENTTASK JOBSERVER_FIFO" BB_BASEHASH_IGNORE_VARS ?= "${BB_HASHEXCLUDE_COMMON} PSEUDO_IGNORE_PATHS BUILDHISTORY_DIR \
SSTATE_DIRSOURCE_DATE_EPOCHRUST_BUILD_SYSRUST_HOST_SYSRUST_TARGET_SYS"BB_HASHCONFIG_IGNORE_VARS?= "${BB_HASHEXCLUDE_COMMON} DATE TIMESSH_AGENT_PID\
--
2.41.0
Hi Martin,
I tested this RFC series briefly when it was posted but then some things came up and I haven't gotten back to it.
I was talking with Richard and he thought that his original poky-contrib branch commit, which it seems this work is based, had a list of things to fix before the jobserver could be merged. Can you find and share that list here?
I may have time to do more testing but I think I had concluded that the default settings:
INHERIT += "jobserver"
didn't have any impact on build performance, as expected, I suppose.
What testing have you done so far?
../Randy
Quoted 129 lines · Martin Hundeb?ll via lists.openembedded.org
Add a class to implement the gnu make fifo style jobserver. The class can be activated by symply adding an
INHERIT += "jobserver"to the local configuration.Furthermore, one can configure an external jobserver (i.e. a server shared between multiple builds), by configured the
JOBSERVER_FIFOvariable to point at an existing jobserver fifo.The jobserver class uses the fifo style jobserver, which doesn't require passing open file descriptors around. It does, however, require make-4.4, which isn't available in common distro yet. To work around this, the class make all recipes (except make and its dependencies itself) depend on
virtual/make-native.Signed-off-by Martin Hundebøll<[email protected]>--- meta/classes-global/jobserver.bbclass | 80 +++++++++++++++++++++++++++ meta/conf/bitbake.conf | 2 +- 2 files changed, 81 insertions(+), 1 deletion(-)create mode 100644 meta/classes-global/jobserver.bbclass
meta/classes-global/jobserver.bbclass new file +80
-0@@ -0,0 +1,80 @@ +JOBSERVER_FIFO ?= "" +JOBSERVER_FIFO[doc] = "Path to external jobserver fifo to use instead of creating a per-build server." + +addhandler jobserver_setup_fifo +jobserver_setup_fifo[eventmask] = "bb.event.ConfigParsed" + +python jobserver_setup_fifo() { + # don't setup a per-build fifo, if an external one is configured + if d.getVar("JOBSERVER_FIFO"): + return + + # don't use a job-server if no parallelism is configured + jobs = oe.utils.parallel_make(d) + if jobs in (None, 1): + return + + # reduce jobs by one as a token has implicitly been handed to the + # process requesting tokens + jobs -= 1 + + fifo = d.getVar("TMPDIR") + "/jobserver_fifo" + + # and old fifo might be lingering; remove it + if os.path.exists(fifo): + os.remove(fifo) + + # create a new fifo to use for communicating tokens + os.mkfifo(fifo) + + # fill the fifo with the number of tokens to hand out + wfd = os.open(fifo, os.O_RDWR) + written = os.write(wfd, b"+" * jobs) + if written != (jobs): + bb.error("Failed to fil make fifo: {} != {}".format(written, jobs)) + + # configure the per-build fifo path to use + d.setVar("JOBSERVER_FIFO", fifo) +} + +python () { + # don't configure the fifo if none is defined + fifo = d.getVar("JOBSERVER_FIFO") + if not fifo: + return + + # avoid making make-native or its dependencies depend on make-native itself + if d.getVar("PN") in ( + "make-native", + "libtool-native", + "pkgconfig-native", + "automake-native", + "autoconf-native", + "m4-native", + "texinfo-dummy-native", + "gettext-minimal-native", + "quilt-native", + "gnu-config-native", + ): + return + + # don't make unwilling recipes depend on make-native + if d.getVar('INHIBIT_DEFAULT_DEPS', False): + return + + # make other recipes depend on make-native to make sure it is new enough to + # support the --jobserver-auth=fifo:<path> syntax (from make-4.4 and onwards) + d.appendVar("DEPENDS", " virtual/make-native") + + # disable the "-j <jobs>" flag, as that overrides the jobserver fifo tokens + d.setVar("PARALLEL_MAKE", "") + d.setVar("PARALLEL_MAKEINST", "") + + # set and export the jobserver in the environment + d.appendVar("MAKEFLAGS", " --jobserver-auth=fifo:" + fifo) + d.setVarFlag("MAKEFLAGS", "export", "1") + + # ignore the joberserver argument part of MAKEFLAGS in the hash, as that + # shouldn't change the build output + d.appendVarFlag("MAKEFLAGS", "vardepvalueexclude", "| --jobserver-auth=fifo:" + fifo) +}meta/conf/bitbake.conf +1
-2@@ -946,7 +946,7 @@ BB_HASHEXCLUDE_COMMON ?= "TMPDIR FILE PATH PWD BB_TASKHASH BBPATH BBSERVER DL_DI BB_WORKERCONTEXT BB_LIMITEDDEPS BB_UNIHASH extend_recipe_sysroot DEPLOY_DIR \ SSTATE_HASHEQUIV_METHOD SSTATE_HASHEQUIV_REPORT_TASKDATA \ SSTATE_HASHEQUIV_OWNER CCACHE_TOP_DIR BB_HASHSERVE GIT_CEILING_DIRECTORIES \ - OMP_NUM_THREADS BB_CURRENTTASK" + OMP_NUM_THREADS BB_CURRENTTASK JOBSERVER_FIFO" BB_BASEHASH_IGNORE_VARS ?= "${BB_HASHEXCLUDE_COMMON} PSEUDO_IGNORE_PATHS BUILDHISTORY_DIR \ SSTATE_DIR SOURCE_DATE_EPOCH RUST_BUILD_SYS RUST_HOST_SYS RUST_TARGET_SYS" BB_HASHCONFIG_IGNORE_VARS ?= "${BB_HASHEXCLUDE_COMMON} DATE TIME SSH_AGENT_PID \ -=-=-=-=-=-=-=-=-=-=-=-Links: You receive all messages sent to this group.
View/Reply Online (#186824):https://lists.openembedded.org/g/openembedded-core/message/186824 Mute This Topic:https://lists.openembedded.org/mt/101009092/3616765
Group Owner:[email protected] Unsubscribe:https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Signature · 2 lines
# Randy MacLeod # Wind River Linux